﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Applib.SqlUtilities;
using System.IO;
using System.Data.SqlClient;
namespace QuickTest
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] bs = File.ReadAllBytes(@"1.png");
            string cmd = "INSERT INTO [TSQL2012].[dbo].[image]  VALUES(@name, @Image)";
            SqlDataUtility.ExecuteNonQuery(
                cmd,
                false,
                new SqlParameter("@name", Guid.NewGuid().ToString().Substring(0, 4)),
                new SqlParameter("@Image", bs) { SqlDbType = System.Data.SqlDbType.Image });

            cmd = "select img from [TSQL2012].[dbo].[image]";

            var result = SqlDataUtility.ExecuteScalar(
                                        cmd,
                                        false,
                                        null);

            System.Data.DataTable dt = new System.Data.DataTable("aaa");
            dt.Columns.Add("name", typeof(string));
            dt.Columns.Add("img", typeof(byte[]));
            SqlDataUtility.Query("select * from [TSQL2012].[dbo].[image]", dt);

            bs = null;
            bs = result as byte[];
            File.WriteAllBytes("test.jpg", bs);
        }
    }
}
